import 'package:fluwx/fluwx.dart';

class WechatPayUtils {
  Fluwx flutterWx = Fluwx();
  late Function(WeChatResponse) responseListener;

  WechatPayUtils._internal();

  static final WechatPayUtils _instance = WechatPayUtils._internal();

  factory WechatPayUtils() {
    return _instance;
  }

  void initFlutterWX() {
    flutterWx.registerApi(
        appId: 'wx20bdf249241ce720',
        universalLink: 'https://ahpsvr.anyeoa.com/');
  }

  void flutterWxPay() {
    flutterWx.authBy(
        which: NormalAuth(
            scope: 'snsapi_userinfo', state: 'wechat_sdk_demo_test'));
    responseListener = (response) {
      if (response is WeChatPaymentResponse) {

      }
    };
    flutterWx.addSubscriber(responseListener);
  }

  void removeSubscriber() {
    flutterWx.removeSubscriber(responseListener);
  }
}
